package org.example.controller;

import org.example.common.Constant;
import org.example.entity.SysUser;
import org.example.service.ISysUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping(value = "/cas/login",method = RequestMethod.POST )
public class LoginController {

    @Resource
    private ISysUserService sysUserService;

    @PostMapping
    public Result login(@RequestParam String username, @RequestParam String password, HttpSession session){
        System.out.println(username);
        System.out.println(password);
        SysUser sysUser = sysUserService.findUserByUsername(username);
        if(sysUser==null){
            return Result.buildFail("用户名或密码错误");
        }else{
            session.setAttribute(Constant.USER_INFO_ATTR,sysUser);
            return Result.buildSuccess(sysUser);

        }

    }
}
